package com.hrm.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hrm.dto.EmpDepDTO;
import com.hrm.dto.EmpScalesRatingDTO;
import com.hrm.entity.EmpScalesRating;
import com.hrm.entity.Employee;
import com.hrm.entity.MyPage;
import com.hrm.service.EmpScalesRatingService;
import com.hrm.utils.JsonMsg;
import com.hrm.utils.Layui;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Auther: zy
 * @Date: 2020/5/29 10:11
 * @Description: 员工考勤
 */
@Controller
@RequestMapping("/empScalesRating")
public class EmpScalesRatingController extends BaseController{

    @Autowired
    EmpScalesRatingService empScalesRatingService;

    /**
     * 跳转到员工考勤查询页面
     * @return String
     */
    @RequestMapping("/empScales.html")
    public String empScales(){
        return "dailyManagement/empScales";
    }

    @RequestMapping("/empScalesInfo/{approverId}.html")
    public String empScalesInfo(Model model, @PathVariable(value = "approverId")Integer approverId){
        EmpScalesRating empScalesRating = new EmpScalesRating();
        empScalesRating.setApproverId(approverId);
        model.addAttribute("empScalesInfo",empScalesRating);
        return "dailyManagement/empScalesInfo";
    }

    @RequestMapping("/empScalesList.html")
    @ResponseBody
    public ResponseEntity<Layui> empDepList(MyPage myPage){
        PageHelper.startPage(myPage.getPageNum(),myPage.getPageSize());
        Employee employeeSession = (Employee) session.getAttribute("user");
        List<EmpScalesRatingDTO> empScalesRatingDTOList = empScalesRatingService.empScalesList(employeeSession.getDeptId());
        PageInfo pageInfo = new PageInfo(empScalesRatingDTOList,5);
        Layui layui = Layui.data(pageInfo.getTotal(),pageInfo.getList());
        return ResponseEntity.ok(layui);
    }

    @RequestMapping("/insertEmpScales.html")
    @ResponseBody
    public JsonMsg insertEmpScales(EmpScalesRating empScalesRating){
        empScalesRatingService.insertEmpScalesRecord(empScalesRating);
        return JsonMsg.success();
    }
}
